package org.infodavid.common.ejb;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.infodavid.common.IBuilder;
import org.infodavid.common.annotations.AImplementation;
import org.infodavid.common.annotations.AImplementation.ERuntime;
import org.infodavid.common.ejb.components.EMailComponent;
import org.infodavid.common.ejb.components.GenericPropertiesMapComponent;
import org.infodavid.common.ejb.components.GenericPropertyComponent;
import org.infodavid.common.ejb.components.GeoLocationComponent;
import org.infodavid.common.ejb.components.ImageDataComponent;
import org.infodavid.common.ejb.components.LocationComponent;
import org.infodavid.common.ejb.components.OwnerDetailsComponent;
import org.infodavid.common.ejb.components.PhoneComponent;
import org.infodavid.common.ejb.components.SecuredObjectIdentifierComponent;
import org.infodavid.common.ejb.components.SecurityIdentifierComponent;
import org.infodavid.common.ejb.components.UriComponent;
import org.infodavid.common.impl.ObjectFactoryImpl.BuilderImpl;
import org.infodavid.common.impl.model.DefaultModelFactory;
import org.infodavid.common.model.IApplicationSettings;
import org.infodavid.common.model.IDocument;
import org.infodavid.common.model.IDocumentCategory;
import org.infodavid.common.model.IDocumentVersion;
import org.infodavid.common.model.IGenericPropertiesMap;
import org.infodavid.common.model.IGenericProperty;
import org.infodavid.common.model.IImageData;
import org.infodavid.common.model.IOrganization;
import org.infodavid.common.model.IPerson;
import org.infodavid.common.model.ITemplate;
import org.infodavid.common.model.ITemplateCategory;
import org.infodavid.common.model.ITemplateVersion;
import org.infodavid.common.model.IUser;
import org.infodavid.common.model.IUserConnection;
import org.infodavid.common.model.IUserGroup;
import org.infodavid.common.model.IUserSession;
import org.infodavid.common.model.ModelFactory;
import org.infodavid.common.model.components.IEMail;
import org.infodavid.common.model.components.IGeoLocation;
import org.infodavid.common.model.components.ILocation;
import org.infodavid.common.model.components.IOwnerDetails;
import org.infodavid.common.model.components.IPhone;
import org.infodavid.common.model.components.IUri;
import org.infodavid.common.model.security.IAccessControlEntry;
import org.infodavid.common.model.security.IAccessControlList;
import org.infodavid.common.model.security.ISecuredObjectIdentifier;
import org.infodavid.common.model.security.ISecurityIdentifier;
import org.infodavid.common.persistence.IBasicDataObject;

/**
 * The Class DefaultModelFactory.
 */
@AImplementation(value = ModelFactory.class, runtime = ERuntime.DEFAULT)
public class BeanModelFactory extends DefaultModelFactory {

	/** The logger. */
	private static final Log LOGGER = LogFactory.getLog(BeanModelFactory.class);

	/**
	 * Constructor.
	 * @throws NoSuchMethodException The exception
	 */
	protected BeanModelFactory() throws NoSuchMethodException {
		super();

		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("Adding mappings of concrete classes");
		}

		final Map<Class<? extends IBasicDataObject>,IBuilder<? extends IBasicDataObject>> mappings =
		    getMappings();

		mappings.put(IPerson.class, new BuilderImpl<IPerson>(PersonBean.class));
		mappings.put(IOrganization.class, new BuilderImpl<IOrganization>(OrganizationBean.class));
		mappings.put(IPhone.class, new BuilderImpl<IPhone>(PhoneComponent.class));
		mappings.put(IEMail.class, new BuilderImpl<IEMail>(EMailComponent.class));
		mappings.put(IUri.class, new BuilderImpl<IUri>(UriComponent.class));
		mappings.put(ILocation.class, new BuilderImpl<ILocation>(LocationComponent.class));
		mappings.put(IGeoLocation.class, new BuilderImpl<IGeoLocation>(GeoLocationComponent.class));
		mappings.put(IOrganization.class, new BuilderImpl<IOrganization>(OrganizationBean.class));
		mappings.put(IUserGroup.class, new BuilderImpl<IUserGroup>(UserGroupBean.class));
		mappings.put(IUser.class, new BuilderImpl<IUser>(UserBean.class));
		mappings.put(IUserConnection.class, new BuilderImpl<IUserConnection>(UserConnectionBean.class));
		mappings.put(IImageData.class, new BuilderImpl<IImageData>(ImageDataComponent.class));
		mappings.put(IOwnerDetails.class, new BuilderImpl<IOwnerDetails>(OwnerDetailsComponent.class));
		mappings.put(IDocument.class, new BuilderImpl<IDocument>(DocumentBean.class));
		mappings.put(IDocumentVersion.class, new BuilderImpl<IDocumentVersion>(
		    DocumentVersionBean.class));
		mappings.put(IDocumentCategory.class, new BuilderImpl<IDocumentCategory>(
		    DocumentCategoryBean.class));
		mappings.put(IAccessControlList.class, new BuilderImpl<IAccessControlList>(
		    AccessControlListBean.class));
		mappings.put(IAccessControlEntry.class, new BuilderImpl<IAccessControlEntry>(
		    AccessControlEntryBean.class));
		mappings.put(ISecuredObjectIdentifier.class, new BuilderImpl<ISecuredObjectIdentifier>(
		    SecuredObjectIdentifierComponent.class));
		mappings.put(ISecurityIdentifier.class, new BuilderImpl<ISecurityIdentifier>(
		    SecurityIdentifierComponent.class));
		mappings.put(IApplicationSettings.class, new BuilderImpl<IApplicationSettings>(
		    ApplicationSettingsBean.class));
		mappings.put(ITemplate.class, new BuilderImpl<ITemplate>(TemplateBean.class));
		mappings.put(ITemplateVersion.class, new BuilderImpl<ITemplateVersion>(
		    TemplateVersionBean.class));
		mappings.put(ITemplateCategory.class, new BuilderImpl<ITemplateCategory>(
		    TemplateCategoryBean.class));
		mappings.put(IUserSession.class, new BuilderImpl<IUserSession>(UserSessionBean.class));
		mappings.put(IGenericPropertiesMap.class, new BuilderImpl<IGenericPropertiesMap>(
		    GenericPropertiesMapComponent.class));
		mappings.put(IGenericProperty.class, new BuilderImpl<IGenericProperty>(GenericPropertyComponent.class));
	}
}
